package com.boarsoft.boar.batch.biz;

import com.boarsoft.boar.batch.entity.BatchSummary;
import com.boarsoft.common.Util;
import com.boarsoft.hibernate.biz.SimpleBizImpl;
import org.springframework.stereotype.Component;

import javax.transaction.Transactional;

@Component
public class BatchSummaryBizImpl extends SimpleBizImpl implements BatchSummaryBiz{
    @Override
    @Transactional
    public String save(BatchSummary o) {
        if (Util.strIsEmpty(o.getId())) {
            this.getDao().save(o);
        } else {
            this.getDao().update(o);
        }
        return o.getId();
    }

    @Override
    @Transactional
    public BatchSummary findById(String id) {
        return this.dao.get(BatchSummary.class, id);
    }

    @Override
    @Transactional
    public BatchSummary findByBatchId(String batchId) {
        StringBuilder sb = new StringBuilder();
        sb.append(" and vBatchId = '").append(batchId).append("'");
        BatchSummary bs = dao.find(BatchSummary.class, sb.toString());
        return bs;
    }
}
